import 'package:flutter/material.dart';

class HomeList extends StatelessWidget {
  const HomeList({super.key, required this.notifyList});

  final List notifyList;

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        // 标题
        Container(
          margin: const EdgeInsets.only(bottom: 10),
          child: Row(
            children: [
              Image.asset(
                'assets/images/notice@2x.png',
                width: 24,
                height: 24,
              ),
              const SizedBox(width: 5),
              const Text(
                '社区',
                style: TextStyle(
                  color: Colors.black,
                  fontWeight: FontWeight.w700,
                  fontSize: 16,
                ),
              ),
              const Text(
                '公告',
                style: TextStyle(
                  color: Color(0xFFFF9500),
                  fontWeight: FontWeight.w700,
                  fontSize: 16,
                ),
              ),
            ],
          ),
        ),

        // 列表
        ListView.separated(
          shrinkWrap: true, // 解决列表嵌套不渲染问题
          physics: const NeverScrollableScrollPhysics(), // 禁用滚动条
          itemCount: notifyList.length,
          separatorBuilder: (context, index) => const SizedBox(height: 15),
          itemBuilder: (context, index) {
            final item = notifyList[index];
            return GestureDetector(
              onTap: () {
                // 跳转到详情页，并传递id参数
                Navigator.pushNamed(
                  context,
                  '/detail',
                  arguments: item['id'],
                );
              },
              child: Container(
                padding: const EdgeInsets.all(15),
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(10),
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      item['title'],
                      style: const TextStyle(
                        fontWeight: FontWeight.w700,
                        fontSize: 16, // 标题字体大小
                      ),
                    ),
                    const SizedBox(height: 10), // 间距
                    Text(
                      item['content'],
                      style: const TextStyle(
                        fontSize: 14, // 内容字体大小
                        height: 1.5, // 行高
                        color: Color(0xFF333333), // 文字颜色
                      ),
                    ),
                    const SizedBox(height: 10), // 间距
                    Text(
                      item['createdAt'],
                      style: const TextStyle(
                        fontSize: 12, // 时间字体大小
                        color: Color(0xFF999999), // 时间颜色更浅一些
                      ),
                    ),
                  ],
                ),
              ),
            );
          },
        ),
      ],
    );
  }
}
